-
Notifications
You must be signed in to change notification settings - Fork 1.4k
✨ KCP: add KubeadmControlPlaneTemplate type #4904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ykakarap thanks for this PR!
Could you kindly enable web hooks for the new type ensuring that template type applies the same defaulting & validation rules of the actual type, otherwise this could trigger continuous reconcile loop down the path when comparing the desired state (the KubeadmControlPlaneTemplate object) with the actual state (the instance of KubeadmControlPlane generated from the template)?
controlplane/kubeadm/config/rbac/kubeadmcontrolplanetemplate_editor_role.yaml
Outdated
Show resolved
Hide resolved
controlplane/kubeadm/config/rbac/kubeadmcontrolplanetemplate_viewer_role.yaml
Outdated
Show resolved
Hide resolved
controlplane/kubeadm/config/samples/controlplane_v1alpha4_kubeadmcontrolplanetemplate.yaml
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nits
@@ -0,0 +1,56 @@ | |||
/* | |||
Copyright The Kubernetes Authors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copyright The Kubernetes Authors. | |
Copyright 2021 The Kubernetes Authors. |
Usually we add the year when the file was added here (I have no idea if that's mandatory though) (applies to all new files with copyright header)
SchemeBuilder.Register(&KubeadmControlPlaneTemplate{}, &KubeadmControlPlaneTemplateList{}) | ||
} | ||
|
||
// KubeadmControlPlaneTemplateResource describes the data needed to create an KubeadmControlPlane from a template. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// KubeadmControlPlaneTemplateResource describes the data needed to create an KubeadmControlPlane from a template. | |
// KubeadmControlPlaneTemplateResource describes the data needed to create a KubeadmControlPlane from a template. |
nit
acd0ff3
to
2142049
Compare
@fabriziopandini @sbueringer thanks for the review. I addressed all the PR comments. Can you please review this again? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nits
) | ||
|
||
// log is for logging in this package. | ||
var kubeadmcontrolplanetemplatelog = logf.Log.WithName("kubeadmcontrolplanetemplate-resource") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know the loggers are auto-generated, but the info messages do not add anything. Plus IIRC, controller-runtime logs all the webhook requests it receives. So that is covered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@srm09 Afaik it doesn't log them on the default log level. But I wouldn't add log statements here. When we do it we should do it across the repo.
"sigs.k8s.io/cluster-api/util/version" | ||
) | ||
|
||
func (s *KubeadmControlPlaneSpec) validate(namespace string) (allErrs field.ErrorList) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more suggestion about the method, since we are refactoring it, let's. break this down into smaller chunks aimed at specific parts of the object. For example, a separate method for s.Replicas
, RolloutStrategy
and so on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for that suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm usually we don't break it down that far. Not really against splitting it up, but if it was intended as more or less one func per field I think that's a bit much.
@fabriziopandini wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, some of the providers to see to be breaking down the validations to smaller functions. Ref: https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/master/api/v1alpha4/azuremachine_validation.go#L31-L59
/assign @srm09 |
controlplane/kubeadm/api/v1alpha4/kubeadmcontrolplane_default.go
Outdated
Show resolved
Hide resolved
controlplane/kubeadm/api/v1alpha4/kubeadmcontrolplanetemplate_types.go
Outdated
Show resolved
Hide resolved
controlplane/kubeadm/api/v1alpha4/kubeadmcontrolplanetemplate_webhook.go
Outdated
Show resolved
Hide resolved
/test pull-cluster-api-verify |
@fabriziopandini addressed all the comments on the PR and all pipelines are green. |
thanks for taking care of all the comments! |
controlplane/kubeadm/api/v1alpha4/kubeadmcontrolplanetemplate_webhook.go
Show resolved
Hide resolved
|
||
if !reflect.DeepEqual(r.Spec.Template.Spec, old.Spec.Template.Spec) { | ||
allErrs = append(allErrs, | ||
field.Invalid(field.NewPath("KubeadmControlPlaneTemplate", "spec", "template", "spec"), r, kubeadmControlPlaneTemplateImmutableMsg), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
field.Invalid(field.NewPath("KubeadmControlPlaneTemplate", "spec", "template", "spec"), r, kubeadmControlPlaneTemplateImmutableMsg), | |
field.Invalid(field.NewPath("spec", "template", "spec"), r, kubeadmControlPlaneTemplateImmutableMsg), |
Afaik we usually don't add the kind
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type. | ||
func (r *KubeadmControlPlaneTemplate) ValidateCreate() error { | ||
spec := r.Spec.Template.Spec | ||
allErrs := valdiateKubeadmControlPlaneSpec(spec, r.Namespace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allErrs := valdiateKubeadmControlPlaneSpec(spec, r.Namespace) | |
allErrs := validateKubeadmControlPlaneSpec(spec, r.Namespace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typos 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use the Intellij spellchecker. ;)
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type. | ||
func (r *KubeadmControlPlaneTemplate) ValidateUpdate(oldRaw runtime.Object) error { | ||
var allErrs field.ErrorList | ||
old := oldRaw.(*KubeadmControlPlaneTemplate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually seem to check if the type case works and then return an error (instead of a panic which would happen otherwise), e.g.:
oldM, ok := old.(*Machine)
if !ok {
return apierrors.NewBadRequest(fmt.Sprintf("expected a Machine but got a %T", old))
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also fix it in the KubeadmControlPlane webhook please? (that one was already there before your PR :))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the checks in both the places now :)
I dont think the check was present before (or atleast I didnt find it 😅 ).
Anyway, it should be taken care now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was referring to that one:
prev := old.(*KubeadmControlPlane) |
Thx! |
/lgtm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: vincepri The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
/lgtm |
What this PR does / why we need it:
Add KubeadmControlPlaneTemplate type to controlplane provider. This type will be used by ClusterClass.
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #4901